<?php
namespace Admin\Behavior;
use Common\Lib\Util\ToolUtil;
use Think\Behavior;

class LoginBehavior extends Behavior{

    //后台登录logo配置
    private $logoConfig = array(
        'Building' => array(
            'login_background' => 'bg-login.jpg',
            'login_logo' => 'img-login-tit.png'
        ),
        'Space' => array(
            'login_background' => 'bg-login_space.jpg',
            'login_logo' => 'img-login-tit-space.png'
        )
    );
	
	public function run(&$params) {
		$this->checkUser();
	}
	
	private function checkUser(){
		$userInfo = session('userInfo');
		$moduleUrl = sprintf('%s/%s',MODULE_NAME,CONTROLLER_NAME);
        if (strtolower($moduleUrl) == strtolower('Admin/Login')) {
            $curController = explode('/',C('DEFAULT_CONTROLLER'));
            ToolUtil::assign($this->logoConfig[array_shift($curController)]);
        }
		if (empty($userInfo)){
			if (strtolower($moduleUrl) == strtolower('Admin/Login')) {
				return false;
			}
			redirect(U('Admin/Login/login'));
		}

	}
}